﻿using AutoMapper;
using B.S.DataBase.SuYuan.Domains.Entites;
using B.S.DataBase.SuYuan.ErrorCode;
using B.S.DataBase.SuYuan.Infrastructure.Interfaces;
using B.S.DataBase.SuYuan.Write.API.Applications.Commands.ShopInfo;
using MediatR;

namespace B.S.DataBase.SuYuan.Write.API.Applications.CommandHandlers.ShopInfo
{
    public class TuPicCreateCommandHandler:IRequestHandler<TuPicCreateCommand,APIResult<object>>
    {
        private readonly IBaseRepository<Imgs> iRepo;
        private readonly IMapper mapper;

        public TuPicCreateCommandHandler(IBaseRepository<Imgs>iRepo,IMapper mapper)
        {
            this.iRepo = iRepo;
            this.mapper = mapper;
        }

        public async Task<APIResult<object>> Handle(TuPicCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = ResultCode.添加成功;
            result.Msg =  ResultCode.添加成功.ToString();
            var model = mapper.Map<Imgs>(request);
            model.BatchId =  request.BatchId;
            model.ImgUrl = request.ImgUrl;
            model.ImgType = "产品检测报告";
            model.CreateName = request.CreateName;
            model.CreateTime = DateTime.Now;
            await iRepo.Add(model);
            return await Task.FromResult(result);   



        }



    }


}
